package guavatest.collections;

import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;

import java.util.Set;

/**
 * @Auther : yxpweb
 * @Date : 2021/8/10 17:23
 * @Description: 不可变集合 http://ifeve.com/google-guava-immutablecollections/
 */
public class UnChangeableCollection {

    public static void main(String[] args) {
        ImmutableSet<String> COLOR_NAME = ImmutableSet.of("red", "orange", "yellow");
        ImmutableSet<String> strings = ImmutableSet.copyOf(COLOR_NAME);
        ImmutableSortedSet<String> of = ImmutableSortedSet.of("a", "b", "c", "a", "d", "b");
        System.out.println(of);


    }


}

class Foo {
    Set<Bar> bars;

    Foo(Set<Bar> bars) {
        this.bars = ImmutableSet.copyOf(bars); // defensive copy!
    }

}

class Bar {

}
